package com.smcaiot.jfttask.domain;

import com.smcaiot.jfttask.config.TestMybatisPlusConfig;
import com.smcaiot.jfttask.config.TestSpringConfig;
import com.smcaiot.jfttask.south.port.TaskFlowRepository;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Author: cz
 * @Date: 2023/10/8
 * @Description:
 */
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringRunner.class)
//@PowerMockIgnore( {"javax.management.*", "javax.net.*"})
@PrepareForTest(TaskFlowId.class)
@ContextConfiguration(classes = {TestMybatisPlusConfig.class, TestSpringConfig.class})
public class TaskFlowRepositoryIT {
    @Autowired
    private TaskFlowRepository taskFlowRepository;
    private TaskId taskId = TaskId.from("34534-4353-ghfd-xexred3-34d");
    private TaskBatchId taskBatchId = TaskBatchId.from("4h46j-3j4h5-ghfd-xexred3-34d");
    private TaskFlowId taskFlowId = TaskFlowId.from("5h5h5-44j4j-ghfd-xexred3-34d");

    @Before
    public void setUp() throws Exception {
        PowerMockito.mockStatic(TaskFlowId.class);
        PowerMockito.when(TaskFlowId.next()).thenReturn(taskFlowId);
        PowerMockito.when(TaskFlowId.from(Mockito.anyString())).thenReturn(taskFlowId);

        taskFlowRepository.deleteByTaskFlowId(taskFlowId);
    }

    @Test
    public void should_find_task_flow_after_save_task_flow() {
        //given
        //when
        TaskFlowId returnFlowId = taskFlowRepository.saveTaskFlow(taskId, taskBatchId,
                TaskFlowStatus.TASK_LOG_STATUS_CREATE);
        //then
        TaskFlow taskFlow = taskFlowRepository.findByTaskFlowId(returnFlowId);
        Assertions.assertThat(taskFlow).isNotNull();
        Assertions.assertThat(taskFlow.getTaskFlowId()).isEqualTo(taskFlowId);
    }
}
